package com.alu4r.atcrowdfunding.util;

import com.alu4r.atcrowdfunding.bean.Permission;

import java.util.HashMap;
import java.util.Map;

/**
 * 封装json，通用的一个处理消息，可以返回给客户端
 */
public class JsonMessageResult {
    //设置一个状态码100表示成功，200表示失败
    private int code;

    //提示信息
    private String message;

    //返回给浏览器的信息
    private Map<String, Object> extend = new HashMap<>();

    //返回成功的一个对象
    public static JsonMessageResult success(){
        JsonMessageResult jsonMessageResult = new JsonMessageResult();
        jsonMessageResult.setCode(100);
        jsonMessageResult.setMessage("处理成功");
        return jsonMessageResult;
    }
    //返回一个失败的对象
    public static JsonMessageResult fail(){
        JsonMessageResult jsonMessageResult = new JsonMessageResult();
        jsonMessageResult.setCode(200);
        jsonMessageResult.setMessage("处理失败");
        return jsonMessageResult;
    }

    @Override
    public String toString() {
        return "JsonMessageResult{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", extend=" + extend +
                '}';
    }

    //链式添加map数据
    public JsonMessageResult add(String key, Object object){
        this.getExtend().put(key, object);
        return this;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getExtend() {
        return extend;
    }

    public void setExtend(Map<String, Object> extend) {
        this.extend = extend;
    }

}
